/**
 * Copyright 2002 Cordys R&D B.V. 
 * 
 * This file is part of the Cordys .NET Connector. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 #ifdef PUREUM
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <glib.h>
#include <xmlLib.h>
#endif

#ifdef HASH_ELEMENT
#include "phjLib.h"
#endif /* HASH_ELEMENT */

#ifdef  __cplusplus
extern "C"	{
#endif

/***********************
 * The functions below perform some basic functionality
 * to map integers to valid XML handles. If HASH_ELEMENT
 * is defined (on AS400) then pointers are stored in a hash table
 * and a lookup needs to be done.
 */

#ifdef HASH_ELEMENT

#define getXmlNode(handle)		((tHXmlNode)phjGetAddress((int)handle))
#define getXmlNodeId(node)		((int)phjGetXmlNodeId((void*)node))
#define getXmlDoc(handle)		((tHXmlDoc)phjGetAddress((int)handle))
#define getXmlDocId(node)		((int)phjGetId((void*)node))

//#define deleteXqyDocId(handle)	phjDeleteId((int)handle)
#define deleteXmlDocId(handle)	phjDeleteId((int)handle)
#define deleteXmlNodeId(handle)	0

#else	/* HASH_ELEMENT */

#define getXmlNode(pointer)		((tHXmlNode)pointer)
#define getXmlNodeId(node)		((int)node)
#define getXmlDoc(handle)		((tHXmlDoc)handle)
#define getXmlDocId(node)		((int)node)

//#define deleteXqyDocId(handle)	0
#define deleteXmlDocId(handle)	0
#define deleteXmlNodeId(handle)	0

#endif	/* HASH_ELEMENT */

#define GetUCharFromString(Mstring) (GetUCharForStr(Mstring))

#ifdef  __cplusplus
}
#endif


/***************************************************************************************
	Function Declarations in for Mutex Operations
***************************************************************************************/
void xjaGetMutex();
void xjaReleaseMutex();
tHGstDoc xjaGetInMemoryStream();
void xjaReleaseInMemoryStream();

/**********************************************************************
Unmanaged methods  declrations.
These methods are invoked from the Managed functions
**********************************************************************/

int UMCreateDocument();

int UMReadBytes(int,unsigned char *,int);

int UMReadFromFile(int doc_handle, unsigned char * pbytes);

int UMCreateElementNode(int , unsigned char * , int );

// New for BP
int UMCreateElementNodeWithParentNS(int , unsigned char * , int );

int UMCreateDataNode(int doc_handle, unsigned char * textStr , int parentNode);

int UMCreateDataElement(int doc_handle, unsigned char * elementStr, unsigned char * textStr , int parentNode);

// New for BP
int UMCreateDataElementWithParentNS(int doc_handle, unsigned char * elementStr, unsigned char * textStr , int parentNode);

void UMLockDoc(int doc_handle);

void UMUnLockDoc(int doc_handle);

char*  UMDataToCharArray(int node ,const char* tag, bool* virtualAlloc );

// New for BP
char*  UMDataToCharArrayNS(int node, const char* tag, const char* uri, bool* virtualAlloc );

/***********************************************************
	  Declarations of unmanaged methods in the Node.cpp
***********************************************************/

int  UMXmlAttrPrefix(int node , int index ,unsigned char * prefix);

char* UMXmlGetData(int node, bool* virtualAlloc);

const char* UMXmlGetDataElement(int node ,const unsigned char * tagName, bool* virtualAlloc);

// New for BP
const char* UMXmlGetDataElementNS(int node, const unsigned char * tagName, const unsigned char * uri, bool* virtualAlloc);

void UMWriteToFile(int fromNode ,int toNode ,const unsigned char * fileName ,int pretty);

const char * UMXmlWriteToByteArray(int fromNode,int toNode, int pretty);

int UMXmlWriteToStream(int fromNode,int toNode, int pretty,tHGstDoc stream);
